﻿using FinalPointSet.Model.Manager;
using FinalPointSet.ViewModel.Page;
using FinalPointSet.ViewModel.Page.MainView;
using System.Windows.Controls;
using System.Windows.Input;

namespace FinalPointSet.View.Page.MainView
{
    /// <summary>
    /// SettingPage.xaml 的交互逻辑
    /// </summary>
    public partial class SettingPage : System.Windows.Controls.Page
    {
        private readonly SettingPageViewModel viewModel;
        public SettingPage()
        {
            InitializeComponent();
            //初始化ViewModel
            viewModel = (SettingPageViewModel)DataContext;
        }

        private void TextBox_PreviewKeyDown(object sender, KeyEventArgs e)
        {
            TextBox textBox = (TextBox)sender;
            string textBoxName = textBox.Name;
            //根据TextBox的名称判断
            switch (textBoxName)
            {
                case "TBSearchViewInput":
                    viewModel.HotKeySettingInput(e, HotKeyManager.SearchView);
                    break;
                case "TBMainViewInput":
                    viewModel.HotKeySettingInput(e, HotKeyManager.MainView);
                    break;
                default:
                    break;
            }
            // 检查是否按下了Ctrl+A  
            if ((Keyboard.Modifiers == ModifierKeys.Control) && (e.Key == Key.A))
            {
                // 阻止Ctrl+A的全选操作  
                e.Handled = true;
            }
        }
        private void TextBox_PreviewKeyUp(object sender, KeyEventArgs e)
        {
            viewModel.HotKeySettingEndInput(e, HotKeyManager.SearchView);
        }

        private void TextBox_PreviewMouseMove(object sender, MouseEventArgs e)
        {
            e.Handled = true;
        }

        protected override void OnPreviewMouseDown(MouseButtonEventArgs e)
        {
            TextBoxFocusHolder.Focus();
            // 继续处理默认的鼠标按下事件
            base.OnPreviewMouseDown(e);
        }

        private void Page_Loaded(object sender, System.Windows.RoutedEventArgs e)
        {
            viewModel.InitHotKeyState();
        }
    }
}
